package lec07.pm;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Vector;

public class GetIndexDemo {
	public static void main(String[] args) {
		long start = System.currentTimeMillis();

		//arrayTest();//0ms
		//vectorTest();//15ms
		//arrayListTest();//15ms
		//linkedListTest();//13391ms
		//linkedListTest2();//16ms
		linkedListTest3();//16ms
		long end = System.currentTimeMillis();
		System.out.println(end - start+"ms");
	}

	/**
	 * 
	 */
	private static void arrayTest() {
		int a[] = new int[100000];
		for (int i = 0; i < a.length; i++)
			a[i] = i;
		for (int i = 0; i < a.length; i++)
			a[i]++;
	}
	private static void vectorTest() {
		Vector<Integer> v = new Vector<Integer>();
		for (int i = 0; i <100000; i++)
			v.add(i);
		for (int i = 0; i < v.size(); i++)
			v.get(i);
	}
	private static void arrayListTest() {
		ArrayList<Integer> v = new ArrayList<Integer>();
		for (int i = 0; i <100000; i++)
			v.add(i);
		for (int i = 0; i < v.size(); i++)
			v.get(i);
	}
	private static void linkedListTest() {
		LinkedList<Integer> v = new LinkedList<Integer>();
		for (int i = 0; i <100000; i++)
			v.add(i);
		for (int i = 0; i < v.size(); i++)
			v.get(i);
	}
	private static void linkedListTest2() {
		int k;
		LinkedList<Integer> v = new LinkedList<Integer>();
		for (int i = 0; i <100000; i++)
			v.add(i);
		for (Integer i:v)
			 k=i+1;
	}
	private static void linkedListTest3() {
		int k;
		LinkedList<Integer> v = new LinkedList<Integer>();
		for (int i = 0; i <100000; i++)
			v.add(i);
		Iterator<Integer> it=v.iterator();
		while(it.hasNext())
		{
			Integer cur=it.next();
			k=cur+1;
		}
	}
}
